package com.ebupt.migu.music.system.controller;

import com.ebupt.migu.music.common.auth.IDAuthUtils;
import com.ebupt.migu.music.common.entity.ResultObject;
import com.ebupt.migu.music.common.util.ReqestParamUtil;
import com.ebupt.migu.music.system.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 部门信息
 *
 * @author liuzz
 */
@EnableAutoConfiguration
@Controller
@RequestMapping("/system/dept")
public class DeptController {

    @Autowired
    private HttpServletRequest request;
	@Autowired
	private IDAuthUtils idAuthUtils;
    @Autowired
    DeptService deptService;
    @Resource
    private ReqestParamUtil reqestParamUtil;

    /**
     * 查询全部部门信息
     *
     * @return 部门对象列表
     */
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResultObject<Object> queryAll() {
        ResultObject<Object> retObj = new ResultObject<>();
        // 获取当前用户信息
        Map<String, Object> params = ReqestParamUtil.getParamsWithUserInfo(request);
        // 当前用户是否超级管理员
        params = idAuthUtils.isAdmin(params);
        retObj.setData(deptService.queryAll(params));
        return retObj;
    }

    /**
     * 【用户群管理专用】
     * <br>
     * 查询部门信息
     *
     * @return 部门集合
     */
    @PostMapping("/queryDept")
    @ResponseBody
    public ResultObject<List<Map<String, Object>>> queryDept() {
        // 获取当前用户信息
        Map<String, Object> params = reqestParamUtil.getParams2(request);
        params = idAuthUtils.isAdmin(params);
        params = idAuthUtils.isFullAmountGroupsAdmin(params);
        return deptService.queryDept(params);
    }
}